package net.elive.tools;

public final class ByteShortSwitch { 

	public static void main(String args[] ) {
    	System.out.println("sdfsdfsdf");
        short i = 32000;
        
        byte[] b = new byte[2];   //整型到字节，
        toByteArray(i,b,0);
        short k=toShort(b,0);//字节到整型，转换回来 
        System.out.println(k);    

    }      
    // 将iSource转为长度为iArrayLen的byte数组，字节数组的低位是整型的低字节位 
    public static byte[] toByteArray(short iSource,byte[] byt,int offset) {
        for ( int i = 0; (i < 2) && (i < 2); i++) { 
            byt[i+offset] = (byte)( iSource>>8*i & 0xFF );            
        }
        return byt; 
    }

     // 将byte数组bRefArr转为一个整数,字节数组的低位是整型的低字节位 
    public static short toShort(byte[] bRefArr,int offset) { 
        short iOutcome = 0; 
        byte bLoop;         
        for ( int i =0; i<2 ; i++) { 
            bLoop = bRefArr[i+offset]; 
            iOutcome+= (long)(bLoop & 0xFF) << (8*i);
        }
        return iOutcome; 
    }      
     
}